package com.system.vote.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.system.vote.admin.entity.TVote;
import com.system.vote.admin.entity.TVoteItem;
import com.system.vote.admin.entity.TWxUserinfo;
import com.system.vote.admin.service.TVoteService;
import com.system.vote.admin.mapper.TVoteMapper;
import com.system.vote.core.customBean.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【t_vote(投票表)】的数据库操作Service实现
 * @createDate 2023-10-26 17:20:40
 */
@Service
public class TVoteServiceImpl extends ServiceImpl<TVoteMapper, TVote>
        implements TVoteService {


    @Autowired
    private TVoteMapper tVoteMapper;

    @Override
    public TVote getTVoteByTitle(String title) {
        return getOne(new QueryWrapper<TVote>().eq("title", title));
    }

    @Override
    public Long getTVoteAutoId(TVote tVote) {
        int rows = tVoteMapper.insert(tVote);
        if (rows > 0) {
            TVote currentVoteItem = tVoteMapper.selectById(tVote.getId());
            if (currentVoteItem != null) {
                return currentVoteItem.getId();
            } else {
                return 0L;
            }
        } else {
            return 0L;
        }
    }

    @Override
    public List<TWxUserinfo> getUserListByItemId(Long id, Long pageNum, Long pageSize) {
        return tVoteMapper.getUserListByItemId(id, pageNum, pageSize);
    }

    @Override
    public int statisticsVoting(Long uid) {
        return tVoteMapper.statisticsVoting(uid);
    }

    @Override
    public int statisticsEndVote(Long uid) {
        return tVoteMapper.statisticsEndVote(uid);
    }

    @Override
    public int statisticsVoted(Long uid) {
        return tVoteMapper.statisticsVoted(uid);
    }
}




